home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbpong1a / blockcod.bas < prev    next >
BASIC Source File  |  1999-08-15  |  5KB  |  167 lines

  1. Attribute VB_Name = "BlockCode"
  2. Public Blcks1(3) As Block
  3. Public Blcks2(3) As Block
  4. Public rcts1(3) As RECT
  5. Public rcts2(3) As RECT
  6.  
  7. Public Sub InitBlocks()
  8.     For i = 0 To UBound(Blcks1)
  9.         Set Blcks1(i) = New Block
  10.         Blcks1(i).Create 305, 123 + (i * 31), 2, 1
  11.     Next i
  12.     For i = 0 To UBound(Blcks2)
  13.         Set Blcks2(i) = New Block
  14.         Blcks2(i).Create 321, 123 + (i * 31), 2, 2
  15.     Next i
  16.     
  17.     For i = 0 To UBound(Blcks1)
  18.         With rcts1(i)
  19.             .Top = Blcks1(i).y
  20.             .Left = Blcks1(i).x
  21.             .Bottom = Blcks1(i).y + 30
  22.             .Right = Blcks1(i).x + 15
  23.         End With
  24.     Next i
  25.     For i = 0 To UBound(Blcks2)
  26.         With rcts2(i)
  27.             .Top = Blcks2(i).y
  28.             .Left = Blcks2(i).x
  29.             .Bottom = Blcks2(i).y + 30
  30.             .Right = Blcks2(i).x + 15
  31.         End With
  32.     Next i
  33. End Sub
  34.  
  35. Public Sub BlitBlocks()
  36.     For i = 0 To UBound(Blcks1)
  37.         If Blcks1(i).bBActive Then Blcks1(i).Blit myScreen.m_lpDDSBack
  38.     Next i
  39.     For i = 0 To UBound(Blcks2)
  40.         If Blcks2(i).bBActive Then Blcks2(i).Blit myScreen.m_lpDDSBack
  41.     Next i
  42. End Sub
  43.  
  44. Public Sub BlockCollisions()
  45.     Dim rball1 As RECT, rball2 As RECT, dr As RECT
  46.     
  47.     With rball1
  48.         .Top = myBall1.y
  49.         .Left = myBall1.x
  50.         .Bottom = myBall1.y + 9
  51.         .Right = myBall1.x + 9
  52.     End With
  53.         
  54.     With rball2
  55.         .Top = myBall2.y
  56.         .Left = myBall2.x
  57.         .Bottom = myBall2.y + 9
  58.         .Right = myBall2.x + 9
  59.     End With
  60.     
  61.     For i = 0 To UBound(Blcks1)
  62.         If Blcks1(i).bBActive Then
  63.             If IntersectRect(dr, rball1, rcts1(i)) Then
  64.                 If dr.Right - dr.Left > dr.Bottom - dr.Top Then
  65.                     myBall1.yvel = -myBall1.yvel
  66.                 Else
  67.                     myBall1.xvel = -myBall1.xvel
  68.                 End If
  69.                 Blcks1(i).strength = Blcks1(i).strength - 1
  70.                 If Blcks1(i).strength < 0 Then Blcks1(i).bBActive = False
  71.                 DSoundCode.PlayBounce2
  72.             End If
  73.         
  74.             If IntersectRect(dr, rball2, rcts1(i)) Then
  75.                 If dr.Right - dr.Left > dr.Bottom - dr.Top Then
  76.                     myBall2.yvel = -myBall2.yvel
  77.                 Else
  78.                     myBall2.xvel = -myBall2.xvel
  79.                 End If
  80.                 Blcks1(i).strength = Blcks1(i).strength - 1
  81.                 If Blcks1(i).strength < 0 Then Blcks1(i).bBActive = False
  82.                 DSoundCode.PlayBounce2
  83.             End If
  84.         End If
  85.     Next i
  86.     
  87.     For i = 0 To UBound(Blcks2)
  88.         If Blcks2(i).bBActive Then
  89.             If IntersectRect(dr, rball1, rcts2(i)) Then
  90.                 If dr.Top - rcts2(i).Top > 0 Then
  91.                     myBall1.yvel = -myBall1.yvel
  92.                 End If
  93.                 If dr.Bottom - rcts2(i).Bottom > 0 Then
  94.                     myBall1.yvel = -myBall1.yvel
  95.                 End If
  96.                 If dr.Left - rcts2(i).Left > 0 Then
  97.                     myBall1.xvel = -myBall1.xvel
  98.                 End If
  99.                 If dr.Right - rcts2(i).Right > 0 Then
  100.                     myBall1.xvel = -myBall1.xvel
  101.                 End If
  102.                 Blcks2(i).strength = Blcks2(i).strength - 1
  103.                 If Blcks2(i).strength < 0 Then Blcks2(i).bBActive = False
  104.                 DSoundCode.PlayBounce2
  105.             End If
  106.         
  107.             If IntersectRect(dr, rball2, rcts2(i)) Then
  108.                 If dr.Top - rcts2(i).Top > 0 Then
  109.                     myBall2.yvel = -myBall2.yvel
  110.                 End If
  111.                 If dr.Bottom - rcts2(i).Bottom > 0 Then
  112.                     myBall2.yvel = -myBall2.yvel
  113.                 End If
  114.                 If dr.Left - rcts2(i).Left > 0 Then
  115.                     myBall2.xvel = -myBall2.xvel
  116.                 End If
  117.                 If dr.Right - rcts2(i).Right > 0 Then
  118.                     myBall2.xvel = -myBall2.xvel
  119.                 End If
  120.                 Blcks2(i).strength = Blcks2(i).strength - 1
  121.                 If Blcks2(i).strength < 0 Then Blcks2(i).bBActive = False
  122.                 DSoundCode.PlayBounce2
  123.             End If
  124.         End If
  125.     Next i
  126. End Sub
  127.  
  128. Public Function RedBlocksRemaining() As Integer
  129.     Dim n As Integer
  130.  
  131.     For i = 0 To UBound(Blcks2)
  132.         If Blcks2(i).bBActive Then n = n + 1
  133.     Next i
  134.     
  135.     RedBlocksRemaining = n
  136. End Function
  137.  
  138. Public Function GreenBlocksRemaining() As Integer
  139.     Dim n As Integer
  140.  
  141.     For i = 0 To UBound(Blcks1)
  142.         If Blcks1(i).bBActive Then n = n + 1
  143.     Next i
  144.     
  145.     GreenBlocksRemaining = n
  146. End Function
  147.  
  148. Public Sub RestoreGreenBlock()
  149.     For i = 0 To UBound(Blcks1)
  150.         If Blcks1(i).bBActive = False Then
  151.             Blcks1(i).bBActive = True
  152.             Blcks1(i).strength = 2
  153.             Exit For
  154.         End If
  155.     Next i
  156. End Sub
  157.  
  158. Public Sub RestoreRedBlock()
  159.     For i = 0 To UBound(Blcks2)
  160.         If Blcks2(i).bBActive = False Then
  161.             Blcks2(i).bBActive = True
  162.             Blcks2(i).strength = 2
  163.             Exit For
  164.         End If
  165.     Next i
  166. End Sub
  167.